<template>
    <div class="safework">
        <div class="content">
            <div class="c-top">
                <div class="c-list">
                    <div class="c-left">
                        项目名称
                    </div>
                    <div class="c-right">
                        <!-- {{dataList.projectName}} -->
                        {{userInfo.departsir == 2?userInfo.pdeptname:dataList.projectName}}
                    </div>
                </div>
                <div class="c-list"
                     @click="showclass">
                    <div class="c-left">
                        申请单位
                        <i class="iconfont icon-required"></i>
                    </div>
                    <div class="c-right">
                        <div class="c-select">{{dataList.deptName}}</div>
                        <img src="../../../../static/images/5.png"
                             @click="showmsg">
                    </div>
                </div>
                <div class="c-list">
                    <div class="c-left">
                        申请拆除日期
                        <i class="iconfont icon-required"></i>
                    </div>
                    <div class="c-right">
                        <datetime :start-date="startDateOn"
                                  v-model="dataList.startDate"
                                  @on-change="changestart"
                                  format="YYYY-MM-DD"
                                  title='开始时间'>
                            <div class="showlisttime">
                                {{dataList.startDate}}
                                <i class="iconfont icon-jinru rightmsg"></i>
                            </div>
                        </datetime>
                    </div>
                </div>
                <div class="c-list"
                     @click="selectAreanew">
                    <div class="c-left">
                        拟定拆除部位
                        <i class="iconfont icon-required"></i>
                    </div>
                    <div class="c-right">
                        <input type="text"
                               placeholder="请选择"
                               disabled
                               v-if="!dataArea">
                        <div class="c-select"
                             v-else>{{dataArea}}</div>
                        <img src="../../../../static/images/5.png">
                    </div>
                </div>
                <div class="c-list"
                     @click="changelistnew">

                    <div class="c-left">
                        拆除防护设施类型
                        <i class="iconfont icon-required"></i>
                    </div>
                    <div class="c-right">
                        <input type="text"
                               placeholder="请选择"
                               disabled
                               v-if="!dataList.typeText">
                        <div class="c-select"
                             v-else>{{dataList.typeText}}</div>
                        <img src="../../../../static/images/5.png">
                    </div>
                </div>
                <div class="c-list"
                     @click="changereson">
                    <div class="c-left">
                        拆除原因
                        <i class="iconfont icon-required"></i>
                    </div>
                    <div class="c-right">
                        <input type="text"
                               placeholder="请选择"
                               disabled
                               v-if="!dataList.reasonText">
                        <div class="c-select"
                             v-else>{{dataList.reasonText}}</div>
                        <img src="../../../../static/images/5.png">
                    </div>
                </div>
                <div class="c-list"
                     @click="changemsuu">
                    <div class="c-left">
                        临时采取安全防护措施
                        <i class="iconfont icon-required"></i>
                    </div>
                    <div class="c-right">
                        <input type="text"
                               placeholder="请选择"
                               disabled
                               v-if="!dataList.protectionText">
                        <div class="c-select"
                             v-else>{{dataList.protectionText}}</div>
                        <img src="../../../../static/images/5.png">
                    </div>
                </div>
                <div class="c-list">
                    <div class="c-left">
                        计划恢复(完工)时间
                        <i class="iconfont icon-required"></i>
                    </div>
                    <div class="c-right">
                        <!--<div class="c-select">请选择</div>
                     <img src="../../../../static/images/5.png"  @click="showmsg" >-->

                        <datetime :start-date="startDateOn"
                                  @on-change="changeend"
                                  v-model="dataList.endDate"
                                  format="YYYY-MM-DD"
                                  title='结束时间'>
                            <div class="showlisttime">
                                {{dataList.endDate}}
                                <i class="iconfont icon-jinru rightmsg"></i>
                            </div>
                        </datetime>
                    </div>
                </div>
                <div class="c-list">
                    <div class="c-left">
                        申请人
                    </div>
                    <div class="c-right">
                        {{dataList.personName}}
                    </div>
                </div>
            </div>
            <div class="line"
                 v-if="ApproveInfo.length>0"></div>
            <div class="form-section"
                 v-if="ApproveInfo.length>0">
                <h3>审批信息</h3>
                <div v-for="(item,index) in ApproveInfo"
                     :key="index"
                     class="list-item">
                    <div class="form-item form-item-style2">
                        <div class="label-title">
                            <label>审批意见</label>
                        </div>
                        <div>
                            <p class="textarea">{{item.Remark}}</p>
                        </div>
                    </div>
                    <div class="form-item form-item-style1">
                        <div class="label-title">
                            <label>审批结论</label>
                        </div>
                        <div>
                            <p>{{item.ApproveResult}}</p>
                        </div>
                    </div>
                    <div class="form-item form-item-style1">
                        <div class="label-title">
                            <label>审批人</label>
                        </div>
                        <div>
                            <p>{{item.ApprovePersonName}}</p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="c-btn">
                <div class="c-submit"
                     @click="submitList">提交</div>

            </div>
        </div>

        <!--获取班组-->
        <div v-transfer-dom>
            <popup v-model="classValue"
                   width="100%">
                <!--<div class="position-horizontal-demo" v-for="(item,index) in classList" @click="selectClass(item)">
            <span class="vux-close">
                {{item.deptName}}
            </span>
          </div>-->

                <div class="newlist">
                    <lookcompany></lookcompany>
                </div>
            </popup>
        </div>

        <div v-transfer-dom>
            <popup v-model="AreaValue"
                   width="100%">
                <!--<div class="position-horizontal-demo" v-for="(item,index) in classList" @click="selectClass(item)">
            <span class="vux-close">
                {{item.deptName}}
            </span>
          </div>-->

                <div>
                    <Area @changemsg="changelist"
                          @canclechange="cancellist"></Area>
                </div>
            </popup>
        </div>

        <!--<div v-transfer-dom>
        <popup v-model="newflagtwo" width="100%">
        <div class="newlistdemo" @click="toclose">
            确认
          </div>
          <div class="position-horizontal-demo"  @click="changeType(999)">
            <span class="vux-close">
                全部
            </span>
            <x-icon type="ios-checkmark-empty"  v-if="allcheck" size="30"></x-icon>
          </div>
          <div v-for="(item,index) in typeList" class="position-horizontal-demo" @click="changeType(index)">
            <span class="vux-close">
                {{item}}
            </span>
            <x-icon type="ios-checkmark-empty" size="30" v-if="checklist[0]"></x-icon>
          </div>
        </popup>
      </div>-->

        <div v-transfer-dom>
            <popup v-model="safeValue"
                   width="100%">
                <div class="newlistdemo"
                     @click="toclose">
                    确认
                </div>
                <div class="vux-popup-dialog-content">
                    <div v-for="(item,index) in safeList"
                         :key="index"
                         class="position-horizontal-demo"
                         @click="changeType(index)">
                        <span class="vux-close">
                            {{item.DeptName}}
                        </span>
                        <x-icon type="ios-checkmark-empty"
                                size="30"
                                v-if="checklist[index]"></x-icon>
                    </div>
                </div>
            </popup>
        </div>

        <div v-transfer-dom>
            <popup v-model="resonseValue"
                   width="100%">

                <div class="newlistdemo"
                     @click="toclosereson">
                    确认
                </div>
                <div class="vux-popup-dialog-content">
                    <div v-for="(item,index) in resonList"
                         :key="index"
                         class="position-horizontal-demo"
                         @click="changenewreaon(index)">
                        <span class="vux-close">
                            {{item.DeptName}}
                        </span>
                        <x-icon type="ios-checkmark-empty"
                                size="30"
                                v-if="checkreson[index]"></x-icon>
                    </div>
                </div>
            </popup>
        </div>

        <div v-transfer-dom>
            <popup v-model="msureValue"
                   width="100%">
                <div class="newlistdemo"
                     @click="toclosemesure">
                    确认
                </div>
                <div class="vux-popup-dialog-content">
                    <div v-for="(item,index) in msureList"
                         :key="index"
                         class="position-horizontal-demo"
                         @click="changemsure(index)">
                        <span class="vux-close">
                            {{item.DeptName}}
                        </span>
                        <x-icon type="ios-checkmark-empty"
                                size="30"
                                v-if="checkmsure[index]"></x-icon>
                    </div>
                </div>
            </popup>
        </div>

        <myMenu></myMenu>
    </div>
</template>

<script>
import { TransferDom, Popup } from 'vux'
import myMenu from '@/commonComponents/menu'
import mixin from '../commonmixin.js'
import lookcompany from '../weightwork/lookcompany'
import Area from './arealist'
const getDate = () => {
    var date = new Date()
    var seperator1 = '-'
    var year = date.getFullYear()
    var month = date.getMonth() + 1
    var strDate = date.getDate()
    if (month >= 1 && month <= 9) {
        month = '0' + month
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = '0' + strDate
    }
    var currentdate = year + seperator1 + month + seperator1 + strDate
    return currentdate
}

const endDate = () => {
    var date = new Date()
    var seperator1 = '-'
    var year = date.getFullYear()
    var month = date.getMonth() + 1
    var strDate = date.getDate()
    if (month >= 1 && month <= 9) {
        month = '0' + month
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = '0' + strDate
    }
    var currentdate = year + seperator1 + month + seperator1 + strDate
    return currentdate
}
export default {
    name: 'App',
    directives: {
        TransferDom
    },
    mixins: [mixin],
    data () {
        return {
            options1: ['A单位'],
            options2: ['安全类'],
            active: 1,
            showflag: false,
            dataList: {
                id: '', //	String	否	拆除申请ID（修改时存在，新增时为空）
                projectName: '', //	String	否	项目名称
                projectId: '', //	String	否	项目ID
                deptName: '', //	String	否	申请单位名称
                deptId: '', //	String	否	申请单位ID
                startDate: getDate(), //	String	否	申请拆除日期
                endDate: endDate(), //	String	否	计划完工时间
                area: '', //	String	否	拟定拆除部位，格式化输入，每个输入区域用“◇”分隔（__区__#楼__层__轴）
                typeText: '', //	String	否	拆除防护设施类型（多选，","分隔）
                reasonText: '', //	String	否	拆除原因（多选，“,”分隔）
                protectionText: '', //	String	否	临时安全防护措施（可多选，","分隔）
                personId: '', //	String	否	申请人ID
                personName: '' //	String	否	申请人名称
            },
            startDateOn: getDate(),
            AreaValue: false,
            newflagtwo: false,
            safeValue: false,
            resonseValue: false,
            safeList: [
                // "安全通道","安全防护棚","防护栏杆","洞口防护","进口防护","外架","施工电梯护驾","门防护架",
                // "安全平网","安全立网","外架底座","隔离区","人行斜道","连墙件","其他"
            ],
            checklist: [],
            resonList: [
                // "施工","改造","影响工作面"
            ],
            checkreson: [],

            msureValue: false,
            msureList: [
                // "专人监护","挂设安全标志",'其他措施'
            ],
            checkmsure: [],
            dataArea: '',
            addflag: true,
            ApproveInfo: []

        }
    },
    components: {
        lookcompany, Popup, Area, myMenu
    },
    computed: {
    },
    watch: {
    },
    created () {
        this.dataList = Object.assign({}, this.dataList, {
            projectName: this.userInfo.deptname,
            projectId: this.userInfo.deptid,
            personName: this.userInfo.username,
            personId: this.userInfo.userid,
            deptName: this.userInfo.deptname,
            deptId: this.userInfo.deptid
        })
        if (this.$route.query.id) {
            this.getdetail()
        }
        this.getArea()
        this.getprojectType()
        this.getprojectReson()
        this.getprojectmsure()
    },
    methods: {
        getArea () {
            let param = {
                'allowPaging': true,
                'business': 'GetAreas',
                'data': {
                    'deptId': this.userInfo.deptid
                },
                'pageIndex': 0,
                'pageSize': 20,
                'tokenId': this.tokenId,
                'userId': this.userId
            }
            this.$axiosAjax.getConfigJson(
                param
            ).then(
                (res) => {
                    this.areaList = res.data.data
                }
            )
        },
        getClass () {
            let param = {
                'allowPaging': true,
                'business': 'GetDeparts',
                'data': {
                    'deptId': this.userInfo.deptid
                },
                'pageIndex': 0,
                'pageSize': 20,
                'tokenId': this.tokenId,
                'userId': this.userId
            }
            this.$axiosAjax.getConfigJson(
                param
            ).then(
                (res) => {
                    this.classList = res.data.data
                }
            )
        },
        getprojectType () {
            let param = {
                'allowPaging': true,
                'business': 'GetDismantleTypes',
                'data': {
                },
                'pageIndex': 0,
                'pageSize': 20,
                'tokenId': this.tokenId,
                'userId': this.userId
            }
            this.$axiosAjax.getConfigJson(
                param
            ).then(
                (res) => {
                    this.safeList = res.data.data
                }
            )
        },
        getprojectReson () {
            let param = {
                'allowPaging': true,
                'business': 'GetDismantleReasons',
                'data': {
                },
                'pageIndex': 0,
                'pageSize': 20,
                'tokenId': this.tokenId,
                'userId': this.userId
            }
            this.$axiosAjax.getConfigJson(
                param
            ).then(
                (res) => {
                    this.resonList = res.data.data
                }
            )
        },
        getprojectmsure () {
            let param = {
                'allowPaging': true,
                'business': 'GetDismantleProtections',
                'data': {
                },
                'pageIndex': 0,
                'pageSize': 20,
                'tokenId': this.tokenId,
                'userId': this.userId
            }
            this.$axiosAjax.getConfigJson(
                param
            ).then(
                (res) => {
                    this.msureList = res.data.data
                }
            )
        },
        changelist (val, val2) {
            this.AreaValue = false
            this.dataArea = val
            this.dataList.area = val2
            console.log(val)
        },
        selectAreanew () {
            this.AreaValue = true
        },
        changelistnew () {
            this.safeValue = true
        },
        toclose () {
            this.safeValue = false
        },
        changestart (val) {
            this.dataList.startDate = val
            let x = new Date(val).getTime() - new Date(this.showsearch.endDate).getTime()
            if (x > 0) {
                this.showsearch.endDate = val
            }
            this.startDateOn = val

            this.$forceUpdate()
        },
        changeend (val) {
            this.showsearch.endDate = val
            this.$forceUpdate()
        },
        changeType (index) {
            console.log(index)
            this.checklist[index] = !this.checklist[index]
            let typeNamelist = []
            this.checklist.forEach(
                (item, index1) => {
                    if (item) {
                        typeNamelist.push(this.safeList[index1].DeptName)
                    }
                }
            )
            this.dataList.typeText = typeNamelist.join(',')
            this.$forceUpdate()
        },
        changereson () {
            this.resonseValue = true
        },
        changenewreaon (index) {
            console.log(index)
            this.checkreson[index] = !this.checkreson[index]
            let typeNamelist = []
            this.checkreson.forEach(
                (item, index1) => {
                    if (item) {
                        typeNamelist.push(this.resonList[index1].DeptName)
                    }
                }
            )
            this.dataList.reasonText = typeNamelist.join(',')
            this.$forceUpdate()
        },
        toclosereson () {
            this.resonseValue = false
        },
        changemsuu () {
            this.msureValue = true
        },
        changemsure (index) {
            console.log(index)
            this.checkmsure[index] = !this.checkmsure[index]
            let typeNamelist = []
            this.checkmsure.forEach(
                (item, index1) => {
                    if (item) {
                        typeNamelist.push(this.msureList[index1].DeptName)
                    }
                }
            )
            this.dataList.protectionText = typeNamelist.join(',')
            this.$forceUpdate()
        },
        toclosemesure () {
            this.msureValue = false
        },
        submitList () {
            console.log(this.dataList)
            if (!this.dataList.area) {
                this.$vux.toast.text('请选择拟定拆除部位')
                return false
            }
            if (!this.dataList.typeText) {
                this.$vux.toast.text('请选择拆除防护设施类型')
                return false
            }
            if (!this.dataList.typeText) {
                this.$vux.toast.text('请选择拆除原因')
                return false
            }
            if (!this.dataList.typeText) {
                this.$vux.toast.text('请选择 临时采取安全防护措施')
                return false
            }
            let sendmethod = 'send'
            // if(this.$route.query.id){
            //     sendmethod = "modify";
            // }
            // if(this.$route.query.id){
            //     sendmethod = "modify";
            // }
            if (!this.addflag) {
                return false
            }
            this.addflag = false
            let param = {
                'allowPaging': true,
                'business': 'SetDismantleJob',
                'method': sendmethod,
                'data': this.dataList,
                'pageIndex': 0,
                'pageSize': 20,
                'tokenId': this.tokenId,
                'userId': this.userId
            }
            this.$vux.loading.show({
                text: '正在提交中...'
            })
            this.$axiosAjax.getConfigJson(
                param
            ).then(
                (res) => {
                    if (res.data.code == 0) {
                        // this.$router.push('/workrisk')
                        this.$router.go(-1)
                    } else {
                        this.addflag = true
                    }
                }
            ).catch(() => {
                this.addflag = true
            })
        },
        getdetail () {
            let param = {
                'allowPaging': true,
                'business': 'GetDismantleJob',
                'data': {
                    'id': this.$route.query.id
                },
                'pageIndex': 0,
                'pageSize': 20,
                'tokenId': this.tokenId,
                'userId': this.userId
            }
            this.$axiosAjax.getConfigJson(
                param
            ).then(
                (res) => {
                    let newarr = res.data.data
                    this.dataList = {
                        id: newarr.Id, //	String	否	起重吊装作业申请ID（修改时存在，新增时为空）
                        projectName: newarr.ProjectName, //	String	否	项目名称
                        projectId: newarr.ProjectId, //	String	否	项目ID
                        deptName: newarr.DeptName, //	String	否	申请单位名称
                        deptId: newarr.deptId, //	String	否	申请单位ID
                        startDate: newarr.StartDate.substring(0, 10), //	String	否	申请拆除日期
                        endDate: newarr.EndDate.substring(0, 10), //	String	否	计划完工时间
                        area: newarr.Area, //	String	否	拟定拆除部位，格式化输入，每个输入区域用“◇”分隔（__区__#楼__层__轴）
                        typeText: newarr.TypeText, //	String	否	拆除防护设施类型（多选，","分隔）
                        reasonText: newarr.ReasonText, //	String	否	拆除原因（多选，“,”分隔）
                        protectionText: newarr.ProtectionText, //	String	否	临时安全防护措施（可多选，","分隔）
                        personId: newarr.PersonId, //	String	否	申请人ID
                        personName: newarr.PersonName //	String	否	申请人名称
                    }
                    //  if(this.dataList.PersonId==this.userInfo.userid){
                    //    this.yself = false;
                    //  }
                    //  console.log(this.dataList)
                    this.dataArea = this.changeposition(newarr.Area)
                    this.ApproveInfo = res.data.data.ApproveInfo
                }
            )
        },
        cancellist () {
            //  this.AreaValue = false;
        },
        changeposition (val) {
            if (!val) {
                return false
            }
            let arr = []
            arr = val.split('◇')
            return `${arr[0]}区${arr[1]}楼${arr[2]}层${arr[3]}轴`
        }
    }
}
</script>

<style scoped lang="less">
.safework {
    background-color: #ebeef3;
    height: 100%;
}
.safework .iconfont {
    margin-right: 0;
    color: #999;
}
.safework .icon-required {
    color: red;
}
.content {
    background-color: #fff;
}
.c-top {
    background-color: #fff;
    padding-left: 20px;
}
.c-list {
    padding: 0 20px 0 0;
    height: 50px;
    line-height: 50px;
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid #efeff4;
    align-items: center;
}
.c-left {
    color: #333;
    font-size: 14px;
    position: relative;
}
.c-left > i {
    position: absolute;
    top: -5px;
    right: -18px;
}
.c-right {
    color: #999;
    font-size: 14px;
    display: flex;
    align-items: center;
}
.c-right input {
    background: #fff;
    text-align: right;
}
.c-right img {
    margin-right: 2px;
}
.c-select {
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    width: 160px;
    margin-right: 6px;
    text-align: right;
    font-size: 14px;
    color: #999;
}
.c-btn {
    height: 113px;
    padding-top: 32px;
}
.c-submit {
    width: 200px;
    height: 40px;
    line-height: 40px;
    text-align: center;
    font-size: 15px;
    color: #fff;
    border-radius: 20px;
    background-color: #2269ff;
    margin: 0 auto;
}
.position-horizontal-demo {
    height: 55px;
    line-height: 55px;
    padding-left: 20px;
    font-size: 16px;
    color: #666;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-right: 20px;
    background-color: #fff;
    border-bottom: 1px solid #ebeef3;
}
.newlist {
    height: 40vh;
}
.safecontent {
    height: 100vh;
    padding-top: 40px;
    position: relative;
    // overflow:scroll
}
.newlistdemo {
    height: 50px;
    line-height: 50px;
    text-align: right;
    padding-right: 20px;
    background: #f4f4f4;
}
.showlisttime {
    color: #999;
    font-size: 14px;
}
.line {
    border-bottom: 10px solid #ebeef2;
}
</style>
<style>
.v-transfer-dom .safework .vux-popup-dialog {
    background-color: #fff;
}
.safework .vux-datetime {
    padding: 0;
}
</style>
